﻿using Microsoft.Win32;
using System.Diagnostics;

namespace XYAC.Framework.WohuaMesExtend.IHI.Extensions
{
    public static class AutoStartupHelper
    {
        private const string StartupKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
        private const string AppName = "XYAC.Framework.WohuaMesExtend.IHI"; //修改为你的应用名称

        public static void SetAutoStartup(bool enable)
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(StartupKey, true))
            {
                if (enable)
                {
                    var processName = Process.GetCurrentProcess().MainModule.FileName;
                    key.SetValue(AppName, processName);
                }
                else
                {
                    key.DeleteValue(AppName, false);
                }
            }
        }

        public static bool IsAutoStartupEnabled()
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(StartupKey, true))
            {
                return key.GetValue(AppName) != null;
            }
        }
    }

}
